<?php
/**
 *                    _ooOoo_
 *                   o8888888o
 *                   88" . "88
 *                   (| -_- |)
 *                    O\ = /O
 *                ____/`---'\____
 *              .   ' \\| |// `.
 *               / \\||| : |||// \
 *             / _||||| -:- |||||- \
 *               | | \\\ - /// | |
 *             | \_| ''\---/'' | |
 *              \ .-\__ `-` ___/-. /
 *           ___`. .' /--.--\ `. . __
 *        ."" '< `.___\_<|>_/___.' >'"".
 *       | | : `- \`.;`\ _ /`;.`/ - ` : | |
 *         \ \ `-. \_ __\ /__ _/ .-` / /
 * ======`-.____`-.___\_____/___.-`____.-'======
 *                    `=---='
 *
 * .............................................
 *          佛祖保佑             永无BUG
 */

namespace App\Admin\Tools;

use Encore\Admin\Grid\Tools\BatchAction;

class sureOrder extends BatchAction
{
    protected $action;

    public function __construct($action)
    {
        $this->action = $action;
    }

    public function script()
    {
        return <<<EOT

                    $('{$this->getElementClass()}').on('click', function() {
                         var ids= selectedRows();
                           console.log(ids);
                           if(ids.length==0){
                           toastr.error('请选择一个订单');
                           return;
                           }
                             layer.msg('确认订单中',
                              {
                                            icon: 16
                           });
                           var id=0;
                           for(var i=0; i<ids.length; i++ ){
                          $.ajax({
                            method: 'post',
                            url: '/admin/order/orders/sureOrders',
                            async:false, 
                            data: {
                                _token:LA.token,
                                ids: ids[i],
                                action: {$this->action}
                            },
                            success: function (data) {
                                if(data.code=='success'){
                                    toastr.success('操作成功');
                                   $.pjax.reload('#pjax-container');
                                }else{
                                   
                                }
                              
                            },
                            error:function(){
                                 toastr.success('操作失败');
                            }
                        });
                       
                     }
                     
                 
                    });

EOT;
    }
}